package base

import (
	"log"
	"os"

	"gopkg.in/yaml.v2"
)

type GSLBLogConf struct {
	Level      string `yaml:"level"`
	File       string `yaml:"log_file"`
	MaxSize    int    `yaml:"max_size"`
	MaxBackups int    `yaml:"max_backups"`
	MaxAge     int    `yaml:"max_age"`
	Env        string `yaml:"env"`
}

type GSLBDnsConf struct {
	Forward string `yaml:"forward"`
	Ipv6    string `yaml:"ipv6"`
	Https   string `yaml:"https"`
	Local   string `yaml:"local"`
}

type GSLBInfra struct {
	KvDns string `yaml:"kv_dns"`
}

type GSLBConf struct {
	Log   GSLBLogConf `yaml:"logger"`
	Dns   GSLBDnsConf `yaml:"dns"`
	Infra GSLBInfra   `yaml:"infra"`
}

func (hconf *GSLBConf) ReadConf(path string) {
	ymlFile, err := os.ReadFile(path)
	if err != nil {
		log.Printf("ReadFile failed:%s", err.Error())
		panic(err)
	}
	err = yaml.Unmarshal(ymlFile, hconf)
	if err != nil {
		log.Printf("Unmarshal failed:%s", err.Error())
		panic(err)
	}
}
